@{
    // Set the layout page and page title
		var view = "~/Views/Public/Account/_LoginView.cshtml";
    
    // Initialize general page variables
    var username = "";
    var password = "";
    var rememberMe = false;

    // Validation
    var isValid = true;
    var usernameErrorMessage = "";
    var passwordErrorMessage = "";

    // If this is a POST request, validate and process data
    if (IsPost) {
        username = Request.Form["username"];
        password = Request.Form["password"];
        rememberMe = Request.Form["rememberMe"].AsBool();
        
        // Validate the user's username
        if (username.IsEmpty()) {
            usernameErrorMessage = "You must specify a username.";
            isValid = false;
        }
        
        // Validate the user's password
        if (password.IsEmpty()) {
            passwordErrorMessage = "You must specify a password.";
            isValid = false;
        }
        
        // Confirm there are no validation errors
        if (isValid) {
            if (WebSecurity.UserExists(username) && WebSecurity.GetPasswordFailuresSinceLastSuccess(username) > 4 && WebSecurity.GetLastPasswordFailureDate(username).AddSeconds(60) > DateTime.UtcNow ) {
                Response.Redirect("~/account/AccountLockedOut");
                return;
            }
 
            // Attempt to login to the Security object using provided creds
            if (WebSecurity.Login(username, password, rememberMe)) {
                var returnUrl = Request.QueryString["ReturnUrl"];
                if (returnUrl.IsEmpty()){
                    Response.Redirect("~/Actions/Admin/");
                } else {
                    Context.RedirectLocal(returnUrl);
                }
            }
            
            // If we arrived here, the login failed; convey that to the user
            isValid = false;
        }    
    }
}
@RenderPage(view, new{ isValid=isValid , username=username , usernameErrorMessage = usernameErrorMessage , passwordErrorMessage = passwordErrorMessage , rememberMe=rememberMe , password=password })